﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MathNet.Spatial.Euclidean;
using MathNet.Spatial.Units;

namespace FDEE.Model
{
    public class PEArc
    {
        readonly Circle2D theCircle;
        readonly Angle startAng, endAng;
        readonly double length;
        /// <summary>
        /// 三点确定圆弧
        /// </summary>
        /// <param name="pt1"></param>
        /// <param name="pt2"></param>
        /// <param name="pt3"></param>
        public PEArc(Point2D pt1, Point2D pt2, Point2D pt3)
        {
            theCircle = Circle2D.FromPoints(pt1, pt2, pt3);
            List<Point2D> tmpList = new List<Point2D>() { pt1, pt2, pt3 };
            var tmpAngArray = from a in tmpList select (-Vector2D.YAxis).SignedAngleTo( (a - theCircle.Center));
            var tmpAngList = tmpAngArray.ToList();
            tmpAngList.Sort();
            startAng = tmpAngList.First();
            endAng = tmpAngList.Last();
            length = (endAng - startAng).Radians * theCircle.Radius;
        }

        public double Length => length;
        public double Radius => theCircle.Radius;
        /// <summary>
        /// 两点加半径确定圆弧
        /// </summary>
        /// <param name="pt1"></param>
        /// <param name="pt2"></param>
        /// <param name="raidus"></param>
        //public PEArc(Point2D pt1,Point2D pt2,double raidus)
        //{
        //    theCircle=Circle2D.

        //}
    }
}
